import { createRouter, createWebHistory } from 'vue-router'
import Layout from '@/Layout/index.vue'
import  { isLogin }  from '@/utils'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'layout',
      component: Layout,
      children: [
        {
          path: '/',
          name: 'dashboard',
          meta: {
            label: '首页',
            icon: 'HomeFilled'
          },
          component: () => import('@v/DashBoard/index.vue')
        },
        {
          path: '/carecourse',
          name: 'carecourse',
          meta: {
            label: '课程管理',
            icon: 'DocumentCopy'
          },
          component: () => import('@v/CateCourse/index.vue')
        },
        {
          path: '/addcourse',
          name: 'addcourse',
          meta: {
            label: '添加课程',
          },
          component: () => import('@v/AddCourse/index.vue')
        },
        {
          path: '/Corder',
          name: 'Corder',
          meta: {
            label: '订单管理',
            icon: 'Reading'
          },
          children: [
            {
              path: '/order',
              name: 'order',
              meta: {
                label: '订单',
                icon: 'House'
              },
              component: () => import('@v/CateOrder/index.vue')
            },
            {
              path: '/refund',
              name: 'refund',
              meta: {
                label: '退款',
                icon: 'House'
              },
              component: () => import('@v/CateRefund/index.vue')
            }
          ]
        },
        {
          path: '/catestudent',
          name: 'catestudent',
          meta: {
            label: '用户管理',
            icon: 'User'
          },
          children: [
            {
              path: '/student',
              name: 'student',
              meta: {
                label: '学员',
                icon: 'House'
              },
              component: () => import('@v/CateStudent/index.vue')
            },
            {
              path: '/lecturer',
              name: 'lecturer',
              meta: {
                label: '讲师',
                icon: 'House'
              },
              component: () => import('@v/CateLecturer/index.vue')
            }
          ]
        },
        {
          path: '/clideshow',
          name: 'clideshow',
          meta: {
            label: '资讯管理',
            icon: 'Comment'
          },
          children: [
            {
              path: '/lideshow',
              name: 'lideshow',
              meta: {
                label: '轮播图',
                icon: 'House'
              },
              component: () => import('@v/CatesLideshow/index.vue')
            },
            {
              path: '/article',
              name: 'article',
              meta: {
                label: '文章',
                icon: 'House'
              },
              component: () => import('@v/CateArticle/index.vue')
            }
          ]
        },
        {
          path: '/cseckill',
          name: 'seckill',
          meta: {
            label: '促销管理',
            icon: 'Connection'
          },
          children: [
            {
              path: '/seckill',
              name: 'seckill',
              meta: {
                label: '秒杀活动',
                icon: 'House'
              },
              component: () => import('@v/CateSeckill/index.vue')
            },
            {
              path: '/coupon',
              name: 'coupon',
              meta: {
                label: '优惠券',
                icon: 'House'
              },
              component: () => import('@v/CateCoupon/index.vue')
            }
          ]
        },
        {
          path: '/system',
          name: 'system',
          meta: {
            label: '系统设置',
            icon: 'Setting'
          },
          component: () => import('@v/CateSystem/index.vue')
        },
      ]
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@v/Login/index.vue')
    },
    {
      path: '/home',
      name: 'home',
      meta: {
        label: '大屏数据',
        icon: 'Setting'
      },
      component: () => import('@v/Home/index.vue')
    },
    {
      path: '/',
      redirect: 'layout',
    },
    {
      path: '/:pathMatch(.*)*',
      name: 'notfound',
      component: () => import('@v/NotFound/index.vue')
    }
  ]
})
router.beforeEach((to)=>{
  if(to.path !== '/login'){
    if(!isLogin()){
      return '/login'
    }
  }
})
export default router
